/* View.h
Copyright (c) 2008 Michael Zahniser
Please note the license terms (MIT license) at the end of this document.

Header file for the View abstract base class, which represents a region of an
SDL window that draws itself and handles events separately from the rest of
the window. An Interface is made up of multiple Views either side-by-side or
stacked on top of each other.
*/

#ifndef __MZ_VIEW_H__
#define __MZ_VIEW_H__

union SDL_Event;
class Surface;
class Interface;



class View {
public:
	View() : interface(0) {}
	virtual ~View() {}


protected:
	// Initialize a view, given the command line arguments for the program.
	// If the view cannot be initialized, this function should return false.
	// NOTE: SDL may not be initialized yet when a View's constructor is called,
	// so all initialization using SDL should be done here instead.
	virtual bool Initialize(const Surface &surface) { return true; }

	// Handle an event. If the event involves (x, y) coordinates, they have been
	// translated such that (0, 0) is the top left corner of this View.
	// This function should return false if this view does not support the given
	// event and wants other views to have a chance to handle it.
	virtual bool Handle(const SDL_Event &event) { return false; }

	// Draw the view in the given surface. The surface is passed as a (shallow)
	// copy so that it is impossible for derived classes to modify View::surface
	// to point to anything other than what Interface assigns to it.
	virtual void Draw(Surface surface) const = 0;

	// For derived classes: get access to the Interface containing this View.
	// For example, this can be used to add a window to the Interface.
	Interface *GetInterface() const { return interface; }


private:
	// Allow Interface to store a pointer to itself in a view.
	friend class Interface;
	Interface *interface;
};



#endif



/* Copyright (c) 2008 Michael Zahniser

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */
